home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_05 / allison / person3.cpp < prev    next >
C/C++ Source or Header  |  1995-03-12  |  573b  |  29 lines

  1. LISTING 22 - Adds the assignment operator and copy constructor to
  2. the Person class
  3. //person3.cpp
  4. #include <iostream.h>
  5. #include <string.h>
  6. #include <new.h>         // for placement new
  7. #include "person3.h"
  8.  
  9. Person::Person(const Person & p)
  10.   : birth(p.birth)
  11. {
  12.     last = clone(p.last);
  13.     first = clone(p.first);
  14.     ssn = clone(p.ssn);
  15. }
  16.  
  17. Person & Person::operator=(const Person & p)
  18. {
  19.     if (this != &p)
  20.     {
  21.         this->Person::~Person();
  22.         new (this) Person(p);
  23.     }
  24.     return *this;
  25. }
  26.  
  27. // (other functions as in Listing 20)
  28.  
  29.